/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package smary.ejb.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *Diese Entität stellt einen Scrum Sprint dar.
 * @author Alex
 */
@Entity
@Table(name = "SPRINT")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Sprint.findAll", query = "SELECT s FROM Sprint s"),
    @NamedQuery(name = "Sprint.findBySprintid", query = "SELECT s FROM Sprint s WHERE s.sprintid = :sprintid"),
    @NamedQuery(name = "Sprint.findBySprintbezeichnung", query = "SELECT s FROM Sprint s WHERE s.sprintbezeichnung = :sprintbezeichnung"),
    @NamedQuery(name = "Sprint.findBySprintbeschreibung", query = "SELECT s FROM Sprint s WHERE s.sprintbeschreibung = :sprintbeschreibung"),
    @NamedQuery(name = "Sprint.findBySprintbeginn", query = "SELECT s FROM Sprint s WHERE s.sprintbeginn = :sprintbeginn"),
    @NamedQuery(name = "Sprint.findBySprintende", query = "SELECT s FROM Sprint s WHERE s.sprintende = :sprintende")})
public class Sprint implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "SPRINTID")
    @GeneratedValue(strategy= GenerationType.AUTO)
    private Integer sprintid;
    @Size(max = 2048)
    @Column(name = "SPRINTBEZEICHNUNG")
    private String sprintbezeichnung;
    @Size(min = 1, max = 32700)
    @Column(name = "SPRINTBESCHREIBUNG")
    private String sprintbeschreibung;
    @Basic(optional = false)
    @NotNull
    @Column(name = "SPRINTBEGINN")
    @Temporal(TemporalType.DATE)
    private Date sprintbeginn;
    @Basic(optional = false)
    @NotNull
    @Column(name = "SPRINTENDE")
    @Temporal(TemporalType.DATE)
    private Date sprintende;

    @OneToMany(mappedBy="sprint")
    protected Set<Task> tasks;
    
    @OneToMany(mappedBy="sprint")
    protected Set<Capacity> capacities;

    public Set<Capacity> getCapacities() {
        return capacities;
    }

    public void setCapacities(Set<Capacity> capacities) {
        this.capacities = capacities;
    }

    
    
    
    @ManyToMany
    @JoinTable(name="Sprint_ScrumTeam",
            joinColumns=
                @JoinColumn(name="SS_SPRINTID",referencedColumnName="SPRINTID"),
            inverseJoinColumns=
            @JoinColumn(name="SS_SCRUMTEAMID",referencedColumnName="SCRUMTEAMID"))
    protected Set<Scrumteam> scrumteams;

    public Set<Scrumteam> getScrumteams() {
        return scrumteams;
    }

    public void setScrumteams(Set<Scrumteam> scrumteams) {
        this.scrumteams = scrumteams;
    }

    public Set<Task> getTasks() {
        return tasks;
    }

    public void setTasks(Set<Task> tasks) {
        this.tasks = tasks;
    }
    
    public Sprint() {
    }

    public Sprint(Integer sprintid) {
        this.sprintid = sprintid;
    }

    public Sprint(Integer sprintid, Date sprintbeginn, Date sprintende) {
        this.sprintid = sprintid;
        this.sprintbeginn = sprintbeginn;
        this.sprintende = sprintende;
    }

    public Integer getSprintid() {
        return sprintid;
    }

    public void setSprintid(Integer sprintid) {
        this.sprintid = sprintid;
    }

    public String getSprintbezeichnung() {
        return sprintbezeichnung;
    }

    public void setSprintbezeichnung(String sprintbezeichnung) {
        this.sprintbezeichnung = sprintbezeichnung;
    }

    public String getSprintbeschreibung() {
        return sprintbeschreibung;
    }

    public void setSprintbeschreibung(String sprintbeschreibung) {
        this.sprintbeschreibung = sprintbeschreibung;
    }

    public Date getSprintbeginn() {
        return sprintbeginn;
    }

    public void setSprintbeginn(Date sprintbeginn) {
        this.sprintbeginn = sprintbeginn;
    }

    public Date getSprintende() {
        return sprintende;
    }

    public void setSprintende(Date sprintende) {
        this.sprintende = sprintende;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (sprintid != null ? sprintid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Sprint)) {
            return false;
        }
        Sprint other = (Sprint) object;
        if ((this.sprintid == null && other.sprintid != null) || (this.sprintid != null && !this.sprintid.equals(other.sprintid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getSprintid() + " " + getSprintbezeichnung();
    }
    
}
